package com.bootcamp.javase.inner.computer;

/**
 * @program: InnerCode
 * @description: test local inner class and anonymous inner class
 * @author: Keyu Li
 * @create: 2021-09-03 20:39
 **/

public class TestCompute {
    public static void main(String[] args) {
        double ic = new InnerClazz().methodInner().divide(11, 12);
        System.out.println(ic);
        double aic = new InnerClazz().methodAnony().multiply(11, 12);
        System.out.println(aic);
    }
}

class InnerClazz {
    ICompute methodInner() {
        class LocalCompuet implements ICompute {

            @Override
            public double add(double a, double b) {
                return a + b;
            }

            @Override
            public double subtract(double a, double b) {
                return a - b;
            }

            @Override
            public double multiply(double a, double b) {
                return a * b;
            }

            @Override
            public double divide(double a, double b) {
                return a / b;
            }
        }
        return new LocalCompuet();
    }

    ICompute methodAnony() {
        return new ICompute() {
            double a,b;

            @Override
            public double add(double a, double b) {
                return a + b;
            }

            @Override
            public double subtract(double a, double b) {
                return a - b;
            }

            @Override
            public double multiply(double a, double b) {
                return a * b;
            }

            @Override
            public double divide(double a, double b) {
                return a / b;
            }
        };
    }
}
